from ChanPin.models import Dingdan
from django import forms
from ChanPin.models import Chanpin
import datetime
import random
###2024/10/15 客户详情页生成订单新增功能###

def generate_ddh():
    date_part = datetime.datetime.now().strftime('%Y%m%d')
    random_part = '{:05d}'.format(random.randint(0, 99999))
    return f"{date_part}{random_part}"

class KeHuDingdanForm(forms.ModelForm):
    """客户资料表单"""
    class Meta:
        model = Dingdan
        #zdddh = generate_ddh()
        fields = ['ddh', 'ddtime', 'dduser', 'ddchanpin']

    def __init__(self, *args, **kwargs):
        super(KeHuDingdanForm, self).__init__(*args, **kwargs)
        self.fields['ddh'].initial = generate_ddh()# 设置初始值 随机订单号


class ChanpinForm(forms.ModelForm):
    class Meta:
      model = Chanpin
      fields = ['title','jiage','jiage_dijia','leibie','gys']

